//
//  Date+Extension.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/26.
//

import Foundation
import UIKit

extension Date {
    /**到秒*/
    static var currentTimeValue: Int {
        get {
            let now = Date()
            let dateFormatter = DateFormatter.init()
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            
            let timeInterval:TimeInterval = now.timeIntervalSince1970
            let timeStamp = Int(timeInterval)

            return timeStamp
   
        }
    }
    
    static var timeText: String {
        get {
            let dateFormatter = DateFormatter.init()
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let time = dateFormatter.string(from: Date.init(timeIntervalSinceNow: 0))
            return time
        }
    }
    
    
    /**当前时间，到分*/
    static var currentMinValue: Int {
        get {
            let now = Date()
            let dateFormatter = DateFormatter.init()
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
            let timeInterval:TimeInterval = now.timeIntervalSince1970
            let timeStamp = Int(timeInterval)

            return timeStamp
        }
    }
    
    
    static func transTimeToMinValue(time: String) -> Int{
        let formatter = DateFormatter.init()
        formatter.dateStyle = .medium
        formatter.timeStyle = .short
        formatter.dateFormat = "yyyy-MM-dd HH:mm"

        let date = formatter.date(from: time)
        if date == nil {
            return 0
        }else {
            let timeInterval:TimeInterval = date!.timeIntervalSince1970
            let timeStamp = Int(timeInterval)
            return timeStamp
        }
    }
    
}

